package com.kedacom.demo.modb.rabbitmq.gateway;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.support.RabbitGatewaySupport;

import com.kedacom.demo.modb.rabbitmq.message.ModbMessage;

/**
 * {@link ModbMessageGateway}的RabbitMQ实现
 * @author luocanfeng
 * @date 2013-1-10
 */
public class RabbitModbMessageGateway extends RabbitGatewaySupport implements ModbMessageGateway {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	public void sendModbMessage(ModbMessage message) {
		super.getRabbitTemplate().convertAndSend(message);
		logger.debug("Sent: {}", ToStringBuilder.reflectionToString(message, ToStringStyle.SHORT_PREFIX_STYLE));
	}

	@Override
	public void sendModbMessage(String routingKey, ModbMessage message) {
		super.getRabbitTemplate().convertAndSend(routingKey, message);
		logger.debug("Sent: {} with routingKey \'{}\'",
				ToStringBuilder.reflectionToString(message, ToStringStyle.SHORT_PREFIX_STYLE), routingKey);
	}

}
